# pyinstaller -F -w .\Qtext.py
from PyQt5.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton
import sys


class TextEditDemo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setWindowTitle("translate format")
        self.resize(800, 600)

        self.btnPress1 = QPushButton("clear")
        self.textEdit = QTextEdit()
        self.btnPress2 = QPushButton("translate")
        # self.btnPress1.resize(50, 30)
        # self.btnPress2 = QPushButton("Button 2")

        layout = QVBoxLayout()
        layout.addWidget(self.btnPress1)
        layout.addWidget(self.textEdit)
        layout.addWidget(self.btnPress2)
        # layout.addWidget(self.btnPress2)
        self.setLayout(layout)

        self.btnPress1.clicked.connect(self.btnPress1_Clicked)
        self.btnPress2.clicked.connect(self.btnPress2_Clicked)
        # self.btnPress2.clicked.connect(self.btnPress2_Clicked)

    def btnPress1_Clicked(self):
        self.textEdit.clear()
        clipboard = QApplication.clipboard()
        text = clipboard.text()
        self.textEdit.setPlainText(text)
        self.btnPress2_Clicked()

    def btnPress2_Clicked(self):
        text = self.textEdit.toPlainText()
        text = text.replace('\n', ' ')
        text = text.replace('- ', '')
        self.textEdit.setPlainText(text)
        clipboard = QApplication.clipboard()
        clipboard.setText(text)
        # self.textEdit.setCur

    #     keyb = Controller()
    #     self.textEdit.selectAll()
    #     with keyb.pressed(Key.ctrl):
    #         keyb.press('c')
    #         keyb.release('c')
    #         keyb.press('c')
    #         keyb.release('c')

    # def btnPress2_Clicked(self):
    #     self.textEdit.setHtml(
    #         "<font color='red' size='6'><red>Hello PyQt5!\nHello</font>"
    #     )


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = TextEditDemo()
    win.show()
    sys.exit(app.exec_())

